﻿using System;
using System.ComponentModel;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Wpf.Commands;

namespace StockholmsStad.Windows.UI.Modules.Maintenance.Models
{
    public class CeremonySettingsPresentationModel : INotifyPropertyChanged
    {
        public event EventHandler<DataEventArgs<CeremonySettingsPresentationModel>> Saved;
        public DelegateCommand<object> SaveCommand { get; private set; }

        public CeremonySettingsPresentationModel()
        {
            SaveCommand = new DelegateCommand<object>(Save);

            PropertyChanged += OnPropertyChangedEvent;
        }

        #region Properties

        public string HeaderInfo
        {
            get { return HeaderNames.CeremonySettings; }
        }

        private int ordinaryPreliminaryBookingEarliestDays;
        public int OrdinaryPreliminaryBookingEarliestDays
        {
            get
            {
                return ordinaryPreliminaryBookingEarliestDays;
            }
            set
            {
                if (!value.Equals(ordinaryPreliminaryBookingEarliestDays))
                {
                    ordinaryPreliminaryBookingEarliestDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("OrdinaryPreliminaryBookingEarliestDays"));
                }
            }
        }

        private int individualPreliminaryBookingEarliestDays;
        public int IndividualPreliminaryBookingEarliestDays
        {
            get
            {
                return individualPreliminaryBookingEarliestDays;
            }
            set
            {
                if (!value.Equals(individualPreliminaryBookingEarliestDays))
                {
                    individualPreliminaryBookingEarliestDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("IndividualPreliminaryBookingEarliestDays"));
                }
            }
        }

        private int ordinaryImpedimentDocReminderAtDays;
        public int OrdinaryImpedimentDocReminderAtDays
        {
            get
            {
                return ordinaryImpedimentDocReminderAtDays;
            }
            set
            {
                if (!value.Equals(ordinaryImpedimentDocReminderAtDays))
                {
                    ordinaryImpedimentDocReminderAtDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("OrdinaryImpedimentDocReminderAtDays"));
                }
            }
        }

        private int individualImpedimentDocReminderAtDays;
        public int IndividualImpedimentDocReminderAtDays
        {
            get
            {
                return individualImpedimentDocReminderAtDays;
            }
            set
            {
                if (!value.Equals(individualImpedimentDocReminderAtDays))
                {
                    individualImpedimentDocReminderAtDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("IndividualImpedimentDocReminderAtDays"));
                }
            }
        }

        private int ordinaryImpedimentDocRemoveBookingAtDays;
        public int OrdinaryImpedimentDocRemoveBookingAtDays
        {
            get
            {
                return ordinaryImpedimentDocRemoveBookingAtDays;
            }
            set
            {
                if (!value.Equals(ordinaryImpedimentDocRemoveBookingAtDays))
                {
                    ordinaryImpedimentDocRemoveBookingAtDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("OrdinaryImpedimentDocRemoveBookingAtDays"));
                }
            }
        }

        private int individualImpedimentDocRemoveBookingAtDays;
        public int IndividualImpedimentDocRemoveBookingAtDays
        {
            get
            {
                return individualImpedimentDocRemoveBookingAtDays;
            }
            set
            {
                if (!value.Equals(individualImpedimentDocRemoveBookingAtDays))
                {
                    individualImpedimentDocRemoveBookingAtDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("IndividualImpedimentDocRemoveBookingAtDays"));
                }
            }
        }

        private int ordinaryFreeTimeMessageLaterThanDays;
        public int OrdinaryFreeTimeMessageLaterThanDays
        {
            get
            {
                return ordinaryFreeTimeMessageLaterThanDays;
            }
            set
            {
                if (!value.Equals(ordinaryFreeTimeMessageLaterThanDays))
                {
                    ordinaryFreeTimeMessageLaterThanDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("OrdinaryFreeTimeMessageLaterThanDays"));
                }
            }
        }

        private int impedimentDocValidMonths;
        public int ImpedimentDocValidMonths
        {
            get
            {
                return impedimentDocValidMonths;
            }
            set
            {
                if (!value.Equals(impedimentDocValidMonths))
                {
                    impedimentDocValidMonths = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("ImpedimentDocValidMonths"));
                }
            }
        }

        private int applicationChangeDateIndividualBookingDays;
        public int ApplicationChangeDateIndividualBookingDays
        {
            get
            {
                return applicationChangeDateIndividualBookingDays;
            }
            set
            {
                if (!value.Equals(applicationChangeDateIndividualBookingDays))
                {
                    applicationChangeDateIndividualBookingDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("ApplicationChangeDateIndividualBookingDays"));
                }
            }
        }

        private int applicationChangeDateOrdinaryBookingDays;
        public int ApplicationChangeDateOrdinaryBookingDays
        {
            get
            {
                return applicationChangeDateOrdinaryBookingDays;
            }
            set
            {
                if (!value.Equals(applicationChangeDateOrdinaryBookingDays))
                {
                    applicationChangeDateOrdinaryBookingDays = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("ApplicationChangeDateOrdinaryBookingDays"));
                }
            }
        }

        #endregion

        private void OnPropertyChangedEvent(object sender, PropertyChangedEventArgs e)
        {
            SaveCommand.RaiseCanExecuteChanged();
        }

        private void Save(object obj)
        {
            OnSaved(new DataEventArgs<CeremonySettingsPresentationModel>(this));
        }

        private void OnSaved(DataEventArgs<CeremonySettingsPresentationModel> e)
        {
            var savedHandler = Saved;

            if (savedHandler != null)
                savedHandler(this, e);
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
